<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User;

class Member extends User
{
    protected $table='park_member';
    protected $primaryKey='uid';
    public $timestamps=false;
    protected $guarded=[];
    
    
    public function parkings()
    {
        return $this->hasMany(Parking::class,'user_id');
    }
    
    public function cars()
    {
        return $this->belongsToMany(Car::class,'park_mycar','uid','CarID');
    }
    
    public function getCredit()
    {
        return $this->attributes['P_credit'];
    }
    public function getCarLimit()
    {
        return config('car.levels')[$this->getUserLevel()]['car_limit'];
    }
    public function getUserLevel()
    {
        return $this->attributes['level']?:1;
    }
    
    public function getIdAttribute()
    {
        return $this->attributes['uid'];
    }
    
}
